import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/public_untilController.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_button.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_scrollView.dart';
import '../../views/login_textInput.dart';
import '../../views/login_timer.dart';
import '../../views/login_title.dart';
import 'logic.dart';

class LoginRegisterPage extends StatefulWidget {
  const LoginRegisterPage({Key? key}) : super(key: key);

  @override
  State<LoginRegisterPage> createState() => _LoginRegisterPageState();
}

class _LoginRegisterPageState extends State<LoginRegisterPage> {
  final LoginRegisterLogic _logic = Get.put(LoginRegisterLogic());

  final HLUntilController _untilController = HLUntilController();

  final FocusNode _phoneNode = FocusNode();
  final FocusNode _codeNode = FocusNode();
  final FocusNode _pwdNode = FocusNode();
  final FocusNode _againPwdNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MGColors.whileColor,
      appBar: HLAppBar(),
      body: HLScrollView(
        padding: EdgeInsets.only(left: 30, right: 30, top: 5),
        nodeList: [_phoneNode, _codeNode, _pwdNode, _againPwdNode],
        children: [
          LoginTitle(title: "注册", assistTitle: "请输入手机号和验证码找回密码"),
          SizedBox(height: 15),
          LoginTextInput(
              hint: "请输入手机号",
              node: _phoneNode,
              controller: _logic.phoneController,
              keyboardType: TextInputType.phone,
              suffixIcon: Icon(
                Icons.phone_iphone_outlined,
                color: MGColors.text3Color,
              )),
          LoginTimer(
              untilController: _untilController,
              controller: _logic.codeController,
              node: _codeNode,
              codeAction: () {
                if (_logic.isPhoneNumber()) {
                  (_untilController.action != null) && _untilController.action!();
                  _logic.sendMessage();
                }
              }),
          LoginTextInput(
            hint: "请输入至少10位包含大小写字母、数字的密码",
            isPassWord: true,
            node: _pwdNode,
            controller: _logic.pwdController,
          ),
          LoginTextInput(
            hint: "请再次输入密码",
            isPassWord: true,
            node: _againPwdNode,
            controller: _logic.againPwdController,
          ),
          Obx(() {
            return MGButton(
              title: "确认",
              padding: EdgeInsets.only(top: 20),
              enable: _logic.isEnable.value,
              buttonAction: _logic.register,
            );
          })
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<LoginRegisterLogic>();
    super.dispose();
  }
}
